package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.Seat;
import com.example.vo.SeatPurchasedVO;
import com.example.service.SeatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "座位管理模块")
@Slf4j
@RestController
@RequestMapping("/api/seats")
public class SeatController {

    @Autowired
    private SeatService seatService;

    //不加@RequestParam，参数需要与名字保持一致 ，加了之后必须有参数
    // 可以指定required = false指定参数非必须
    @ApiOperation("根据场馆,座位类型，座位编号查询座位")
    @GetMapping
    public Result getById(@ApiParam("场馆，1-1号场馆，2-2号场馆,参数非必须") @RequestParam(required = false) Short place,
                          @ApiParam("座位类型，1-1等座，2-2等座，3-3等座，参数非必须")  Short seatType) {
        List<Seat> seatList = seatService.list(place,seatType);
        return Result.success(seatList);
    }

    @ApiOperation("新增座位,只测试用")
    @PostMapping
    public Result save(){
        seatService.save();
        return Result.success();
    }

    @ApiOperation("返回指定赛事的座位被购买情况")
    @GetMapping("/seatPurchased")
    public Result seatPurchased(
            @ApiParam("赛事ID,即eventID") @RequestParam Integer eventID){
        SeatPurchasedVO seatPurchasedVOList = seatService.seatPurchased(eventID);
        return Result.success(seatPurchasedVOList);
    }
}
